<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\UserGroup
 *
 * @property int $id
 * @property int $user_id 发起拼团的用户
 * @property int $system_groups_id 拼的团
 * @property int $course_id 课程id
 * @property int $join_num 加入人数
 * @property int $status 1拼团中，2拼团成功，3拼团失败，4取消拼团
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserGroup newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserGroup newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\UserGroup onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserGroup query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserGroup whereCourseId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserGroup whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserGroup whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserGroup whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserGroup whereJoinNum($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserGroup whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserGroup whereSystemGroupsId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserGroup whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\UserGroup whereUserId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\UserGroup withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\UserGroup withoutTrashed()
 * @mixin \Eloquent
 */
class UserGroup extends Model
{
    use SoftDeletes;
    public static function getUnFinishCourseGroup($course_id){
        if (!$course_id)
            return [];

        $data=self::whereCourseId($course_id)
            ->whereStatus(1)
            ->get();
        $temp=Course::getCourseInfo($course_id);
        if (count($data) > 0){
            foreach ($data as $item){
                $item->course_info  = $temp;
                $item->user_info    = UserInfo::getUserInfo($item->user_id);
                $time               = SystemGroup::getTimeLimit($item->system_groups_id);
                $item->deadline     = $time ? (int)(strtotime($item->created_at) + ($time * 3600)) : 0 ;
                $item->join_user    = UserGroupXUser::getJoinUser($item->id);
            }
        }
        return $data;
    }
}
